﻿using System;
using l1cs.server.model.Instance;
using System.Xml;
using System.Collections;
using System.Collections.Generic;

namespace l1cs.server.model.npc.action
{
    public class L1NpcShowHtmlAction : L1NpcXmlAction
    {
        private String _htmlId;
        private String[] _args;

        public L1NpcShowHtmlAction()
        {
        }

        public L1NpcShowHtmlAction( XmlReader reader )
            : base( reader )
        {
            Hashtable attribute = L1NpcXmlParser.getAllAttribute( reader );
            _htmlId = (string)attribute["HtmlId"];

            List<String> dataList = new List<String>();
            while ( reader.Read() )
            {
                // 開始タグを発見した場合
                if ( reader.NodeType == XmlNodeType.Element )
                {
                    if ( String.Compare( reader.Name, "Data", true ) == 0 )
                    {
                        attribute = L1NpcXmlParser.getAllAttribute( reader );
                        dataList.Add( (string)attribute["Value"] );
                    }
                }
            }
            _args = dataList.ToArray();
        }

        override public L1NpcHtml execute( String actionName, L1PcInstance pc, L1Object obj, byte[] args )
        {
            return new L1NpcHtml( _htmlId, _args );
        }
    }
}